home *** CD-ROM | disk | FTP | other *** search
/ Apple Developer Connection 1998 Fall: Game Toolkit / Disc.iso / SDKs / Apple Game Sprockets / NetSprocket / NewNSpTest Sources / fooutils.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-09-18  |  3.2 KB  |  146 lines  |  [TEXT/CWIE]

  1. /*************************************************************************************
  2. #
  3. #        utils.c
  4. #
  5. #        This segment handles file parsing, and basic utility functions.
  6. #
  7. #        Author(s):     Michael Marinkovich
  8. #                    Apple Developer Technical Support
  9. #                    marink@apple.com
  10. #
  11. #        Modification History: 
  12. #
  13. #            2/10/96        MWM     Initial coding                     
  14. #
  15. #        Copyright © 1992-96 Apple Computer, Inc., All Rights Reserved
  16. #
  17. #
  18. #        You may incorporate this sample code into your applications without
  19. #        restriction, though the sample code has been provided "AS IS" and the
  20. #        responsibility for its operation is 100% yours.  However, what you are
  21. #        not permitted to do is to redistribute the source as "DSC Sample Code"
  22. #        after having made changes. If you're going to re-distribute the source,
  23. #        we require that you make it clear in the source that the code was
  24. #        descended from Apple Sample Code, but that you've made changes.
  25. #
  26. *************************************************************************************/
  27.  
  28. #include <Events.h>
  29. #include <ToolUtils.h>
  30. #include <Gestalt.h>
  31. #include <OSUtils.h>
  32. #include <StandardFile.h>
  33.  
  34. #include "App.h"
  35. #include "Proto.h"
  36.  
  37.  
  38. //----------------------------------------------------------------------
  39. //
  40. //    PictToWorld - create a GWorld from a Pict. Size is determined by the
  41. //                  bounds of the pict. If the pict is nil then a default
  42. //                  bounds is used, in case of an empty window.
  43. //----------------------------------------------------------------------
  44.     
  45. OSErr PictToWorld(PicHandle pict, short depth, GWorldPtr *theWorld)
  46. {
  47.     OSErr            err = noErr;
  48.     GWorldPtr        oldWorld;
  49.     GDHandle        oldGD;
  50.     PixMapHandle    thePix;
  51.     Rect            bounds;
  52.     
  53.     if (theWorld != nil && pict != nil)
  54.     {
  55.         *theWorld = nil;
  56.         bounds = (**pict).picFrame;
  57.  
  58.         GetGWorld(&oldWorld, &oldGD);
  59.                 
  60.         err = NewGWorld(theWorld, depth, &bounds, nil, nil, 0L);
  61.         
  62.         if (err == noErr && theWorld != nil) 
  63.         {
  64.             thePix = GetGWorldPixMap(*theWorld);
  65.             
  66.             if (LockPixels(thePix)) 
  67.             {
  68.                 SetGWorld(*theWorld, nil);
  69.                 
  70.                 EraseRect(&bounds);
  71.                 DrawPicture(pict, &bounds);
  72.                 
  73.                 UnlockPixels(thePix);
  74.             }
  75.             
  76.             SetGWorld(oldWorld, oldGD);
  77.         }
  78.             
  79.     }
  80.     else
  81.         err = paramErr;
  82.     
  83.     
  84.     return err;
  85.     
  86. }
  87.  
  88.  
  89. //----------------------------------------------------------------------
  90. //
  91. //    ZeroRect - zero the top-left points of a rect
  92. //                
  93. //
  94. //----------------------------------------------------------------------
  95.  
  96. void ZeroRect(Rect *r)
  97. {
  98.     Rect        zr;
  99.     
  100.     zr = *r;
  101.     
  102.     if (zr.left < 0)
  103.         OffsetRect(&zr,zr.left,0);
  104.     if (zr.top < 0)
  105.         OffsetRect(&zr,0,zr.top);
  106.     
  107.     OffsetRect(&zr,-zr.left,-zr.top);
  108.     
  109.     *r = zr;
  110.  
  111.  
  112.  
  113. //----------------------------------------------------------------------
  114. //
  115. //    pstrcpy - pascal string copy
  116. //                
  117. //
  118. //----------------------------------------------------------------------
  119.  
  120. void pstrcpy(StringPtr dst, StringPtr src)
  121. {
  122.     short    c;
  123.     
  124.     for (c = *src; c > -1; c--)
  125.         dst[c] = src[c];
  126. }
  127.  
  128.  
  129. //----------------------------------------------------------------------
  130. //
  131. //    pstrcat - pascal string concat
  132. //                
  133. //
  134. //----------------------------------------------------------------------
  135.  
  136. void pstrcat(StringPtr dst, StringPtr src)
  137. {
  138.     
  139.     short    c;
  140.  
  141.     for (c = 1; c < src[0] + 1; c++)
  142.         dst[dst[0] + c] = src[c];
  143.     dst[0] += src[0];
  144. }
  145.